package vumt.radiocountries.adapter;

import java.util.ArrayList;

import vumt.radiocountries.R;
import vumt.radiocountries.object.SubChannelObject;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ChannelBaseAdapter extends BaseAdapter {
	private Context mContext;
	private ArrayList<SubChannelObject> listSubChannel;

	public ChannelBaseAdapter(Context c, ArrayList<SubChannelObject> list) {
		this.mContext = c;
		this.listSubChannel = list;
	}

	@Override
	public int getCount() {
		return listSubChannel.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater mInflater = (LayoutInflater) mContext
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = mInflater
					.inflate(R.layout.item_row_radiostation, parent, false);
			ViewHolder holder = new ViewHolder();
			holder.name = (TextView) v.findViewById(R.id.tvName);
			holder.numChannel = (TextView) v.findViewById(R.id.tvNumChannel);
			v.setTag(holder);
		}

		SubChannelObject subChannel = listSubChannel.get(position);
		if (subChannel != null) {
			ViewHolder holder = (ViewHolder) v.getTag();
			holder.name.setText(subChannel.name);
			holder.numChannel.setText(subChannel.listLink.size() + " Channel ");
		}
		return v;
	}

	static class ViewHolder {
		TextView name;
		TextView numChannel;
	}
}
